package com.ruoyi.back.service.impl

import cn.hutool.core.util.StrUtil
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.back.domain.ContactWay
import com.ruoyi.back.mapper.ContactWayMapper
import com.ruoyi.back.service.ContactWayService
import com.ruoyi.common.core.page.TableSupport
import org.springframework.stereotype.Service

@Service
class ContactWayServiceImpl : ServiceImpl<ContactWayMapper, ContactWay>(), ContactWayService {

    override fun saveContactWay(contactWay: ContactWay): Data<Boolean> =
        contactWay.id?.run {
            Ok("更新成功", updateById(contactWay))
        } ?: Ok("保存成功", save(contactWay))

    override fun contactWayPage(contactWay: ContactWay): Page<ContactWay> =
        TableSupport.buildPageRequest().let { pageDomain ->
            page(Page(pageDomain.pageNum.toLong(), pageDomain.pageSize.toLong()), KtQueryWrapper(ContactWay::class.java)
                .eq(StrUtil.isNotBlank(contactWay.name), ContactWay::name, contactWay.name))
        }

    override fun removeContactWay(contactIds: String): Data<Boolean> =
        Ok("批量移除成功", removeByIds(contactIds.split(",")))
}